package com.bprogram.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bprogram.pojo.Comment;
import com.bprogram.pojo.Video;
import com.bprogram.service.CommentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.List;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author cai
 * @since 2023-11-21
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentService commentService;

    @Resource
    private VideoFeign videoFeign;

    /**
     * 根据视频Id找评论
     *
     * @param videoId     视频Id
     * @param upId        视频发布者Id
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("/getCommentByCondition")
    public IPage<Comment> getCommentListByCondition(long videoId, long upId, String currentPage, String pageSize) {
        return commentService.getCommentListByCondition(videoId, upId, currentPage, pageSize);
    }

    /**
     * @param comment
     * @return
     */
    @PostMapping("/saveComment")
    public boolean saveComment(Comment comment) {

        return commentService.saveComment(comment);
    }

    /**
     * 根据视频id计算评论总数
     * @param videoId
     * @return
     */
    @GetMapping("/getCounts")
    public long getCounts(long videoId){
        QueryWrapper<Comment> wrapper = new QueryWrapper<>();
        wrapper.eq("videoId",videoId);
        return commentService.count(wrapper);
    }

    /**
     * 根据wrapper删除评论
     * @param videoId
     * @return
     */
    @GetMapping("/deleteComment")
    public boolean deleteComment(long videoId){
        QueryWrapper<Comment> wrapper = new QueryWrapper<>();
        wrapper.eq("videoId",videoId);
        return commentService.removeById(wrapper);
    }
}

